CXX := gcc
WARNINGFLAGS := -Wall -Wc++-compat -Wextra
CXXFLAGS := $(WARNINGFLAGS) -g -DDSFMT_MEXP=2203 --pedantic
#CXXFLAGS := $(WARNINGFLAGS) -O2 -DNDEBUG -DDSFMT_MEXP=2203 --pedantic
#CXXFLAGS := $(WARNINGFLAGS) -pg -O3 -g -DDSFMT_MEXP=2203 --pedantic

UNAME = $(shell uname)
ifeq ($(UNAME), Darwin)
OPENGL_FLAGS = -framework OpenGL -framework GLUT
else
OPENGL_FLAGS = -lGL -lGLU -lglut
endif

LIBS := -lm
OBJDIR := obj
INCDIR := inc
SOURCEDIR := src
INCLUDE := -I $(INCDIR)
OBJECTS := $(OBJDIR)/dot_writer.o \
$(OBJDIR)/gate.o \
$(OBJDIR)/module.o \
$(OBJDIR)/mutate.o \
$(OBJDIR)/crossover.o \
$(OBJDIR)/selection.o \
$(OBJDIR)/random_module_generator.o \
$(OBJDIR)/truth_table.o \
$(OBJDIR)/util.o \
$(OBJDIR)/dSFMT.o \
$(OBJDIR)/population.o \
$(OBJDIR)/config.o

elgalso : $(OBJECTS) $(OBJDIR)/main.o
	$(CXX) $(CXXFLAGS) $(LIBS) $^ -o $@

elgalso-gl : LIBS += $(OPENGL_FLAGS)
elgalso-gl : $(OBJECTS) $(OBJDIR)/main_gl.o
	$(CXX) $(CXXFLAGS) $(LIBS) $^ -o $@

all : elgalso elgalso-gl doc

$(OBJDIR)/%.o : $(SOURCEDIR)/%.c
	$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@

doc :
	doxygen ./docs/doxyfile
clean :
	rm -f $(OBJDIR)/*.o
	rm -f elgalso elgalso-gl
	rm -f gmon.out

ultraclean : clean
	rm -f $(INCDIR)/*~
	rm -f $(SOURCEDIR)/*~
	rm -f *~
	rm -f .DS_Store
	rm -f $(INCDIR)/.DS_Store
	rm -f $(SOURCEDIR)/.DS_Store
	rm -rf docs/html
	rm -rf docs/latex
	rm -f docs/.DS_Store
	rm -f docs/*~
	rm -f truths/*~
	rm -f configs/*~
	rm -f *.dot
	rm -f *.png
	rm -f $(SOURCEDIR)/*.dot
	rm -f $(INCDIR)/*.dot
